package com.ets.Codes_DAO;

import com.ets.common.Displayable;
import com.ets.common.DataDictionaryConstants;
import com.ets.common.StringUtils;

/*------------------------------------------------------------------------------
 The <big><b>CodeValue</b></big> class implements the <b>Displayable</b> &
 <b>Cloneable</b> interfaces to create a <b>CodeValue</b> object
 <br><br>
 @author D.Merkling - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.2  
------------------------------------------------------------------------------*/
public class CodeValue implements Displayable, Cloneable, DataDictionaryConstants
  {
   private String Sys;
   private String Sgmt;
   private String Cd;
   private String Val;
   private String Val2;

   /*------------------------------------------------------------------------------
	This constructor creates a new <b>CodeValue</b> object with default values
   ------------------------------------------------------------------------------*/
   public CodeValue ()
	 {
	  this.Sys  = "ETS";
	  this.Sgmt = "00";
	  this.Cd   = " ";
	  this.Val  = " ";
	  this.Val2 = " ";
	 }

   /*------------------------------------------------------------------------------
	This constructor creates a new <b>CodeValue</b> object with attribute values as
	defined by the provided parameters
    <br><br>
	@param Sys A <b><i>String</i></b> variable
	@param Sgmt A <b><i>String</i></b> variable
	@param Cd A <b><i>String</i></b> variable
	@param Val A <b><i>String</i></b> variable
	@param Val2 A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public CodeValue (String Sys, String Sgmt, String Cd, String Val, String Val2)
	 {
	  this.Sys  = Sys;
	  this.Sgmt = Sgmt;
	  this.Cd   = Cd;
	  this.Val  = Val;
	  this.Val2 = Val2;
	 }

   /*------------------------------------------------------------------------------
	Clones a current <b>CodeValue</b> object to create a new one
    <br><br>
	@return CodeValue - A <b>CodeValue</b> object
	@throws CloneNotSupportedException 
   ------------------------------------------------------------------------------*/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*------------------------------------------------------------------------------
	Sets the <b><i>String</i></b> <b>Sys</b> attribute for the current
	<b>CodeValue</b> object
    <br><br>
	The value must be uppercase, trimmed, & left-justified
    <br><br>
	@param Sys A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public void setSys (String Sys)
	 {
	  String tmpSys = Sys.toUpperCase();
	  tmpSys        = tmpSys.trim();
	  this.Sys      = tmpSys;
	 }

   /*------------------------------------------------------------------------------
	Retrieves the <b><i>String</i></b> <b>Sys</b> attribute from the current
	<b>CodeValue</b> object
    <br><br>
	@return Sys - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getSys ()
	 {
	  return Sys;
	 }

   /*------------------------------------------------------------------------------
	Sets the <b><i>String</i></b> <b>Sgmt</b> attribute for the current
	<b>CodeValue</b> object
    <br><br>
	The value must be uppercase, trimmed, & left-justified
    <br><br>
	@param Sgmt A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public void setSgmt (String Sgmt)
	 {
	  String tmpSgmt = Sgmt.toUpperCase();
	  tmpSgmt        = tmpSgmt.trim();
	  this.Sgmt      = tmpSgmt;
	 }

   /*------------------------------------------------------------------------------
	Retrieves the <b><i>String</i></b> <b>Sgmt</b> attribute from the current
	<b>CodeValue</b> object
    <br><br>
	@return Sgmt - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getSgmt ()
	 {
	  return Sgmt;
	 }

   /*------------------------------------------------------------------------------
	Sets the <b><i>String</i></b> <b>Cd</b> attribute for the current
	<b>CodeValue</b> object
    <br><br>
	The value must be uppercase, trimmed, & left-justified
    <br><br>
	@param Cd A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public void setCd (String Cd)
	 {
	  String tmpCd = Cd.toUpperCase();
	  tmpCd        = Cd.trim();
	  this.Cd      = tmpCd;
	 }

   /*------------------------------------------------------------------------------
	Retrieves the <b><i>String</i></b> <b>Cd</b> attribute from the current
	<b>CodeValue</b> object
    <br><br>
	@return Cd - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getCd ()
	 {
	  return Cd;
	 }

   /*------------------------------------------------------------------------------
	Sets the <b><i>String</i></b> <b>Val</b> attribute for the current
	<b>CodeValue</b> object
    <br><br>
	The value must be trimmed & left-justified
    <br><br>
	@param Val A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public void setVal (String Val)
	 {
	  String tmpVal = Val.trim();
	  this.Val      = tmpVal;
	 }

   /*------------------------------------------------------------------------------
	Retrieves the <b><i>String</i></b> <b>Val</b> attribute from the current
	<b>CodeValue</b> object
    <br><br>
	@return Val - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getVal ()
	 {
	  return Val;
	 }

   /*------------------------------------------------------------------------------
	Sets the <b><i>String</i></b> <b>Val2</b> attribute for the current
	<b>CodeValue</b> object
    <br><br>
	The value must be trimmed & left-justified
    <br><br>
	@param Val2 A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public void setVal2 (String Val2)
	 {
	  String tmpVal = Val2.trim();
	  this.Val2     = tmpVal;
	 }

   /*------------------------------------------------------------------------------
	Retrieves the <b><i>String</i></b> <b>Val2</b> attribute from the current
	<b>CodeValue</b> object
    <br><br>
	@return Val2 - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getVal2 ()
	 {
	  return Val2;
	 }

   /*------------------------------------------------------------------------------
	Determines whether or not all of the attribute values of one <b>CodeValue</b>
	object are equal to all of the attribute values of a second <b>CodeValue</b>
	object
    <br><br>
	@param object A	<b>CodeValue</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   ------------------------------------------------------------------------------*/
   public boolean equals (Object object)
     {
      if (object instanceof CodeValue)
        {
         CodeValue cv2 = (CodeValue) object;
         if (Sys.equals(cv2.getSys())   &&
             Sgmt.equals(cv2.getSgmt()) &&
             Cd.equals(cv2.getCd())     &&
             Val.equals(cv2.getVal())   &&
             Val2.equals(cv2.getVal2())   )
         return true;
        }
      return false;
     }

   /*------------------------------------------------------------------------------
	Retrieves a one-line list of the attribute values of the current
	<b>CodeValue</b> object
    <br><br>
	@return string - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String toOneLine ()
	 {
	  return "Code: " + this.Sys  + "-" +
	                    this.Sgmt + "-" +
		                this.Cd   + "-" +
		                this.Val  + "-" +
		                this.Val2;
	 }

   /*------------------------------------------------------------------------------
	Retrieves a one-line formatted list of the attribute values of the current
	<b>CodeValue</b> object for use in a table display
    <br><br>
	@return string - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String toTableString ()
	 {
	  return StringUtils.padWithSpaces(this.Sys,  Sys_LEN)  + " | " +
	         StringUtils.padWithSpaces(this.Sgmt, Sgmt_LEN) + " | " +
	         StringUtils.padWithSpaces(this.Cd,   Cd_LEN)   + " | " +
	         StringUtils.padWithSpaces(this.Val,  Val_LEN)  + " | " +
	         StringUtils.padWithSpaces(this.Val2, Val_LEN);
	 }
   
   /*------------------------------------------------------------------------------
	Retrieves a formatted list of the attribute values of the current
	<b>CodeValue</b> object
    <br><br>
	@return string - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String toString ()
	 {
	  return "System : " + this.Sys  + "\n" +
	         "Segment: " + this.Sgmt + "\n" +
		     "Code   : " + this.Cd   + "\n" +
		     "Value 1: " + this.Val  + "\n" +
		     "Value 2: " + this.Val2 + "\n";
	 }
   
   /*------------------------------------------------------------------------------
	Retrieves a formatted displayable list of the attribute values of the current
	<b>CodeType</b> object
    <br><br>
	@return string - A <b><i>String</i></b> variable
   ------------------------------------------------------------------------------*/
   public String getDisplayText ()
    {
	  return toString();
    }
  }
